/***********************************************************************
 * Module:  Intake.java
 * Author:  Vanil
 * Purpose: Defines the Class Intake
 ***********************************************************************/
package personal;
import db.dao.DoctorDao;
import db.dao.IntakeDao;
import db.dao.PatientDao;
import db.dto.DoctorDto;
import db.dto.IntakeDto;
import db.dto.PatientDto;
import db.exceptions.DoctorDaoException;
import db.exceptions.IntakeDaoException;
import db.exceptions.PatientDaoException;
import db.factory.IntakeDaoFactory;
import db.jdbc.DoctorDaoImpl;
import db.jdbc.IntakeDaoImpl;
import db.jdbc.PatientDaoImpl;

import java.util.*;

public class Intake {
   IntakeDto dto;
    IntakeDao dao;
    public Intake(IntakeDto dto) {
        this.dto = dto;
        dao = IntakeDaoFactory.create();
    }


   public void setDoctor(Doctor newDoctor) throws IntakeDaoException {
       this.dto.setIdDoctor(newDoctor.getIdPerson()); 
   }
    public Doctor getDoctor() throws DoctorDaoException {
       DoctorDao dao = new DoctorDaoImpl();
       DoctorDto doctorDto = dao.findByPrimaryKey(this.dto.getIdDoctor());
       return new Doctor(doctorDto);
   }

   public Patient getPatient() throws PatientDaoException {
       PatientDao dao = new PatientDaoImpl();
       PatientDto patientDto = dao.findByPrimaryKey(this.dto.getIdPatient());
       return new Patient(patientDto);
   }
   

   public void setPatient(Patient newPatient) throws IntakeDaoException {
       dto.setIdPatient(newPatient.getIdPerson());
   }
    public int getId()
    {
        return dto.getIdIntake();
    }
    private void updateUpload() throws IntakeDaoException {
        dao.update(dto.getIdIntake(),dto);
    }
    private void updateDownload() throws IntakeDaoException {
        dto = dao.findByPrimaryKey(dto.getIdIntake());
    }

    public void setDate(Date date) throws IntakeDaoException {
        dto.setDateofintake(date.getTime());
    }
    public Date getDate() throws IntakeDaoException {
        return new Date(dto.getDateofintake());
    }
    public String getComment()
    {
        return dto.getComment();
    }
}